<template>
	<action-bar :screen="isFullScreen" type="home" @onSetUP="onSetUP"></action-bar>
	<view class="">
		<view>
			<image class="height100vh image posiab top0" src="/static/img/changko.png"></image>
			<view class="flex-ju-c height100vh posire zindex5">
				<view class=" height100vh ">
					<view class="width100vw">
						<view class="flex-ju-c hkmk">
							<view class="amt200">
								<view class="flex-ju-b color333 height90">
									<view class="">
										<view class="width100vw flex-ju-c ">
											<view class="flex-a-i mr1600 posire pb20 "  @mouseenter="showinfo" @mouseleave="cancel_info=false">
												<image  v-if="user.avatar"
													class="image mr15 ra110 wh110-110" :src="IMGURL+user.avatar">
												</image>
												<image v-else  mode="widthFix"
													class="image mr15 width110" src="/static/img/xaing.png">
												</image>
												<view >{{user.nickName}}</view>

												<view class="posiab top130 zindex5 hidden "
													:class="cancel_info?'sanimation':'animation'">
													<view @mouseleave="cancel_info=false" class="bgf6faff pg30 ra15" style="box-shadow: 3px 7px 12px 0px rgba(0,0,0,0.10); ">
														<view class="width600 ">
															<view class="flex-a-i ">
																<view class=" posire">
																	<image @click.stop="setimgtou" mode="widthFix"
																		class="image posiab bottom0 right20 width40"
																		src="/static/img/setimg.png"></image>
																	<image v-if="user.avatar"
																		class="image mr15  ra110 wh110-110"
																		:src="IMGURL+user.avatar"></image>

																	<image v-else @mouseenter="showinfo" mode="widthFix"
																		class="image mr15 width110"
																		src="/static/img/xaing.png">
																	</image>

																</view>
																<view>
																	<view @click.stop="tapinfo" class="flex-a-i size36">
																		{{user.nickName}}
																		<image mode="widthFix"
																			class="image ml15 width36"
																			src="/static/img/bianju.png"></image>
																	</view>
																	<view class="flex-a-i size28 color666">
																		我的云会议室：{{priv_room_cuid}}
																		<image @click.stop="copy(priv_room_cuid)"
																			mode="widthFix" class="image ml15 width36"
																			src="/static/img/copy.png"></image>
																	</view>
																</view>
															</view>
														</view>
														<view class="color666 size28">
															<view class="mt20 mb20">登录名：{{user.userName}}</view>
															<view>所属组织：{{user.deptName}}</view>
														</view>
														<view class="bgfff pg30 ra10 size32 mt30 flex-ju-b hover">
															<view class="flex-a-i">
																<image mode="widthFix" class="image mr15 width50"
																	src="/static/img/bendiziyuan.png"></image>
																本地资源
															</view>
															<image mode="widthFix" class="image  width50"
																src="/static/img/zright.png">
															</image>
														</view>
														<view @click="tapposs"
															class="bgfff hover pg30 ra10 size32 mt15 flex-ju-b">
															<view class="flex-a-i">
																<image mode="widthFix" class="image mr15 width50"
																	src="/static/img/mima.png"></image>
																修改密码
															</view>
															<image mode="widthFix" class="image  width50"
																src="/static/img/zright.png">
															</image>
														</view>
														<view @click="tapout"
															class="bgfff hover pg30 ra10 size32 mt15 flex-ju-b">
															<view class="flex-a-i">
																<image mode="widthFix" class="image mr15 width50"
																	src="/static/img/tuichu.png"></image>
																退出登录
															</view>
														</view>
													</view>
												</view>
											</view>
										</view>
									</view>

									<view class="wh300-90 bge8efff flex-ju-c posiab right0"
										style="border-bottom-left-radius:20px;border-top-left-radius:20px;">
										<view @click="$refs.upDrawer.open()" class="color000 flex-a-i ">
											待参加的会议
											<image mode="widthFix" class="image width45" src="/static/img/rights.png">
											</image>
										</view>
									</view>
								</view>

								<!-- //待参加会议 -->
								<meeting-drawer @onSetRoomCuid="onSetRoomCuid" ref="upDrawer"></meeting-drawer>

								<view class="flex-ju-c size32 flex-col ">
									<view class="flex-a-i mt130 mb170">
										<view @click="tapTO(newItem[0])" v-if="newItem[0]"
											class="colorfff flex-ju-c posire zindex0">
											<image mode="heightFix" class="image height456 width460"
												:src="IMGURL+newItem[0].bigFilePath">
											</image>
											<view class="posiab mt160">{{newItem[0].name}}</view>
										</view>
										<view v-if="newItem[1]" @click="tapTO(newItem[1])"
											class="colorfff flex-ju-c posire mr33 ml33 zindex0 ">
											<image mode="heightFix" class="image height456 width460"
												:src="IMGURL+newItem[1].bigFilePath">
											</image>
											<view class="posiab mt160">{{newItem[1].name}}</view>
										</view>


										<view class="flex-ju-b  flex-wrap height456 width930">
											<template v-for="(item,f) in newItem" :key="f">
												<view @click="tapTO(item)" v-if="f>1&&f<6" class="wh448-212">
													<view class="bgfff flex-ju-c wh448-212 ra40 mr33">
														<image mode="heightFix" class="image mr25 height144"
															:src="IMGURL+item.filePath"></image>
														{{item.name}}
													</view>
												</view>
											</template>

										</view>
									</view>
								</view>

								<view class="width1000 color303133 size32 flex-ju-c">

									<template v-for="(item,p) in newItem" :key="p">

										<view @click="tapTO(item)" v-if="p>5&&p<10"
											class="bgfff flex-ju-c ml30 mr30 wh208-212 flex-col ra40">
											<image mode="heightFix" class="image  mb10 height104"
												:src="IMGURL+item.filePath">
											</image>
											<view>{{item.name}}</view>
										</view>

									</template>

								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 修改姓名 -->
		<set-name ref="showmode" :user="user" :type="is_name" @sctrue="infoSctrue"></set-name>

		<!-- 修改密码 -->
		<set-pwd ref="showsetpoww" @sctrue="sctrue"></set-pwd>



		<!-- <tishi ref="showtishi" :isclen="0" bgcolor="#165fff" title="长时间未操作，已自动退出登录！"></tishi> -->

		<!-- 设置 -->
		<configuration @newItem="tapnewItem" :IMGURL="IMGURL" @TAPiscam="TAPiscam" ref="onSetUP"></configuration>
		<!-- 手机下载配置 -->
		<phone-config ref="upPhone"></phone-config>
		<!-- 我的评价 -->
		<my-evaluate ref="pingjia"></my-evaluate>



		<!-- 加入会议 -->
		<push-meeting @pushMeeting="pushMeeting" ref="upaddhuiyi"></push-meeting>

		<!-- 发起会议 -->
		<initiate-meeting @setup="setup" :priv_room_cuid="priv_room_cuid" @startMeeting="startMeeting"
			ref="upfahuiyi"></initiate-meeting>

		<!-- 输入参会密码 -->
		<join-pwd ref="joinPWD" @joinPWD="tapJoinPWD" @confirm="tapJoin"></join-pwd>

		<!-- 会议设置 -->
		<meeting-setup @setName="setName" ref="huiyishez"></meeting-setup>

		<tishi ref="upLogin" isclen="1" bgcolor="#fc474c" title="您确定要退出登录吗？"></tishi>
		<tishi ref="upLogOut" @confirm="onLogOut" logout="1" bgcolor="#fc474c" title="当前账号在其他设备登录？"></tishi>
		
		
		
	</view>
</template>

<script>
	import {
		ElMessage
	} from 'element-plus'

	import {
		lkrequest
	} from '../../js/lk/request.js'
	export default {
		data() {
			return {
				isFullScreen:true,
				is_name: false,
				ismic: true,
				iscam: true,
				nickName: "",
				userName: "",
				timeout: "",
				schedule_index: "",
				calldata: {},
				isdata: false,
				priv_room_cuid: "",
				join_pwd: "",
				ctrl_pwd: "",
				user: "",
				password: "1234",
				username: "dqyptyg2",
				drawer: false,
				time_id: "",
				taht_room_cuid: "",
				meetinglist: [],
				meetinglists: [],
				priv_room_id: "",
				newjoin_pwd: "",
				meetingService: {},
				newItem: [],
				cancel_info: false
			}
		},
		onShow() {
			
			this.isFullScreen= !this.isFullScreen
			
			uni.$off('joinpwd')
			uni.$on('joinpwd', res => {
				this.$refs.joinPWD.open()
			})
			
			uni.$off('callSucceed')
			uni.$on('callSucceed', res => {
				uni.hideLoading()
				uni.navigateTo({
					url: './video'
				})
				this.taht_room_cuid = ''
			})
			uni.$off('onLogOut')
			uni.$on('onLogOut', res => {
				this.$refs.upLogOut.show()
			})
			setTimeout(()=>{
				if (window.loginMgr) {
					loginMgr.put_self_status('1')
				}
			},300)
			
		},
		onLoad() {
			
			if (uni.getStorageSync('info')) {
				let infos = uni.getStorageSync('info')
				this.priv_room_cuid = infos.priv_room_cuid
				this.priv_room_id = infos.priv_room_id
			}

			this.http('/app/meetingService/info').then(res => {
				this.meetingService = res.data
				uni.setStorageSync('meetingService', res.data)
			})

			this.http('/getAppInfo').then(res => {
				if (!uni.getStorageSync('user')) {
					this.logininfo(res)
				}
				uni.setStorageSync('user', res.data)
				this.user = res.data.user
			})

		},
		mounted() {
			 
			if (!uni.getStorageSync('token')) {
				uni.reLaunch({
					url: "/pages/index/login"
				})
			}

			zjsdk3.on_dev_test_device_failed = (is_camera, device_id, reason) => {
				uni.showToast({
					title: "未检测到，请检查",
					icon: "none"
				})
			}
			
		},
		methods: {
			onSetUP() {
				this.$refs.onSetUP.open()
			},
			tapJoinPWD() {
				this.newjoin_pwd = ''
			},

			TAPiscam(e) {
				this.iscam = e
			},
			tapnewItem(itewm) {
				this.newItem = itewm
			},
			tapJoin(pwd) {
				this.newjoin_pwd = pwd
				uni.showLoading()
				this.call_now()
			},
			onSetRoomCuid(taht_room_cuid) {
				this.taht_room_cuid = taht_room_cuid
			},
			call_now() {
				uni.showLoading()
				zjsdk3.make_call_now(this.meetingService.meetingIp, this.meetingService.port, (this.taht_room_cuid ? this
					.taht_room_cuid : this.priv_room_cuid), this.newjoin_pwd, this.user.nickName,uni.getStorageSync('sdkinfo').account)
			},
			pushMeeting(room_cuid, ismic, iscam) {
				this.taht_room_cuid = room_cuid
				this.ismic = ismic
				this.iscam = iscam
				this.call_now()
			},
			tapTO(item) {
				if (item.code == "realTimeMonitor") {
					uni.navigateTo({
						url: "/pages/jiankong/index"
					})
				} else if (item.code == "reservationMeeting") {
					uni.navigateTo({
						url: './meeting?room_id=' + this.priv_room_id
					})
				} else if (item.code == "videoCall") {
					uni.navigateTo({
						url: "/pages/callvideo/index"
					})
				} else if (item.code == "initiateMeeting") {
					this.taht_room_cuid = ''
					this.$refs.upfahuiyi.open()
				} else if (item.code == "joinMeeting") {
					this.taht_room_cuid = ''
					this.$refs.upaddhuiyi.open()
				} else if (item.code == "wheelPatrolPlan") {
					uni.navigateTo({
						url: "/pages/jiankong/patrol"
					})
				} else if (item.code == 'voiceBroadcast') {
					uni.navigateTo({
						url: "/pages/jiankong/broadcast"
					})
				} else {
					uni.showToast({
						title: "开发中",
						icon: "none"
					})
				}
			},


			infoSctrue(name) {
				if(name.length>1&&name.length<20){
					uni.showLoading()
					this.http('/system/user/edit', {
						nickName: name,
						userId: this.user.userId
					}, 'post').then(res => {
						uni.showToast({
							title: "修改成功",
							icon: "none"
						})
						let user = uni.getStorageSync('user')
						user.user.nickName = name
						uni.setStorageSync('user', user)
						this.user.nickName = name
						this.$refs.showmode.close()
						uni.hideLoading()
					})
				}else{
					uni.showToast({
						title: "姓名错误",
						icon: "none"
					})
				}
				
			},
			//回显会议设置
			setup() {
				this.$refs.huiyishez.open()
			},

			get_room_info() {
				uni.showLoading()
				return new Promise((resolve, reject) => {
					loginMgr.get_self_room_info().then(res => {
						resolve(res)
					})
				})
			},




			// 云会议室设置
			setName(room_name, join_pwd, ctrl_pwd) {

				uni.showLoading()
				loginMgr.mod_self_room_info({
					room_name: room_name,
					join_pwd: join_pwd,
					ctrl_pwd: ctrl_pwd
				}).then(res => {
					uni.hideLoading()
					if (res.result == 0) {
						ElMessage({
							message: '设置成功',
							type: 'warning',
						})
						uni.showToast({
							title: "设置成功",
							icon: "none"
						})
						this.$refs.huiyishez.close()
					} else {
						ElMessage({
							message: res.reason,
							type: 'warning',
						})
					}
				})

			},

			startMeeting(ismic, iscam) { //进入会议
				this.ismic = ismic
				this.iscam = iscam
				uni.showLoading()
				this.get_room_info().then(res => {
					loginMgr.select_usr_join_mr(res.cuid).then(ress => {

						if (ress.result == 0) {
							zjsdk3.make_call_now(this.meetingService.meetingIp, this.meetingService
								.port, res.cuid, res.ctrl_pwd, this.user.nickName,uni.getStorageSync('sdkinfo').account)
						} else {
							uni.hideLoading()
							if (ress.code == 7094) {
								ElMessage({
									message: '当前会议室正在使用，请更换会议室',
									type: 'warning',
								})
								return
							} else {
								ElMessage({
									message: ress.reason,
									type: 'warning',
								})
								return
							}
						}

					})
				})


			},

			setimgtou() {

				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album'],
					success: (res) => {
						uni.uploadFile({
							header: {
								'APP': '5415',
								'Authorization': 'Bearer ' + (uni.getStorageSync("token") ? uni
									.getStorageSync("token") : '')
							},
							url: this.geturl('') + '/system/user/profile/avatar',
							filePath: res.tempFilePaths[0],
							name: 'avatarfile',
							formData: {
								'avatarfile': res.tempFilePaths[0]
							},
							success: (uploadFileRes) => {
								this.user.avatar = JSON.parse(uploadFileRes.data).imgUrl
								uni.showToast({
									title: "更新成功",
									icon: "none"
								})
							}
						});

					}
				})
			},
			sctrue(pwass, newpwass, dnewpwass) { //修改密码
				uni.showLoading()
				this.http('/system/user/password/update', {
					userId: this.user.userId,
					oldPassword: pwass,
					password: newpwass,
				}, 'post').then(res => {
					uni.showToast({
						title: "修改成功",
						icon: "none"
					})
					setTimeout(() => {
						uni.setStorageSync('token', '')
						uni.setStorageSync('user', '')
						uni.setStorageSync('info', '')
						uni.setStorageSync('sdkinfo', '')
						uni.reLaunch({
							url: "/pages/index/index"
						})
					}, 700)
				})
			},
			logininfo(res) {
				window.loginMgr = new LoginMgr(res.data.meetingIp, res.data.port, {
					dev_id: res.data.devid,
					dev_token: res.data.devToken
				})
				loginMgr.on_receive_invite = (data) => {
					if(getCurrentPages()[0].route == 'pages/index/video'){//开会中不邀请
						return
					}
					this.calldata = data
					const title = data.conference_name + '的私人会议';
					const body = '邀请您加入视频会议';
					const flag = JSON.stringify(data)
					const avatar = this.IMGURL + this.user.avatar
					flutter.call('callWindow', {
						title,
						body,
						flag,
						avatar
					}, (result, error) => {
						if (error) {
							uni.showToast({
								title: error,
								icon: "none"
							})
							return;
						}
					})
				}
				

				let sre = res.data.meetingUserName.split("@")

				loginMgr.login(sre[0], sre[1], res.data.meetingUserPwd).then(res => {
					if (res.result == 0) {
						uni.setStorageSync('sdkinfo', res.data.results)
						loginMgr.init()
						loginMgr.get_self_info().then(res => {
							this.priv_room_cuid = res.priv_room_cuid
							this.priv_room_id = res.priv_room_id
							uni.setStorageSync('info', res)
							loginMgr.put_self_status('1')
						})

					}
				})

				clearInterval(this.time_id)
				this.time_id = setInterval(() => {
					lkrequest(
						`/user/refresh-token?token=${uni.getStorageSync('user').monitorToken}`, {},
						'post',
						'refresh-token')
				}, 1740000)
			},
		

			tapout() {
				this.$refs.upLogin.show()
			},
			tapposs() {
				this.$refs.showsetpoww.open()
			},
			tapinfo() {
				this.is_name = !this.is_name
				this.$refs.showmode.open()
			},
			showinfo() {
				this.cancel_info = true
			}
		}
	}
</script>

<style>
	/deep/ .el-slider__button-wrapper {
		display: none !important;
	}

	.uni-stat__select {
		width: 100px;
		flex: none;
	}


	/deep/ .viewdrawer {
		background: none;
	}

	/deep/ .el-table--fit .el-table__inner-wrapper:before {
		background: #fff;
	}

	/deep/ .viewdrawer {
		margin-top: 50px;
	}



	/deep/ .sleds .el-select__wrapper {
		border-top-right-radius: 0;
		border-bottom-right-radius: 0;
	}


	/deep/ .el-popper.is-light.el-popover {
		z-index: 10 !important;
	}

	/deep/ .el-popper.is-light.el-popover.povk {
		z-index: 999 !important;
	}

	/* /deep/ .ppphhh {
		z-index: 1000;
	} */


	.hkmk {
		height: calc(100vh - 92rpx)
	}

	.hmfsd:hover {
		color: red;
	}

	.hmfsd {
		text-align: center;
	}

	.denghlu {
		border-bottom: 2px solid #fff;
	}

	.denghlu:hover {
		cursor: pointer;
	}

	.active {
		border-bottom: 2px solid #165FFF;
		font-weight: bold;
	}

	.hover:hover {
		background: #e0eaff;
	}

	.homer:hover {
		background-color: #e8efff;
		color: #165FFF;
	}

	.dashedborder {
		border: 1px dashed #E6E6E6;
	}

	.nowrap {
		white-space: nowrap;
	}

	.xuanxia {
		transform: rotate(180deg);
	}

	.hfcenter {
		display: flex;
		align-items: center;
		padding-left: 10px;
	}
</style>